var statisticsReportData = [];
var deleteFlag = "";
var totalPage;
var totalCnt;

$(document).ready(function() {
	showLoading();
	$('title', parent.document).html($('title').text());
	setBaseUrl();
	createTableHead("statisticsReportThead", statisticsReportTable);
	search();
});
function search(){
	$ajax('searchStatisticsReport', 'statisticsReportForm', searchStatisticsReport);
}

function searchStatisticsReport(data){
	statisticsReportData = data && data.statisticsReportList || [];
	totalPage = data && data.totalPage || 0;
	totalCnt = data && data.totalCnt || 0;
	createTableBody("statisticsReportTbody", statisticsReportTable, statisticsReportData);
}

function save() {
	deleteFlag = "save";
	addTitle("statisticsReportSave");
	allTable();
}
function chkBefore(index, msg){
	deleteFlag = msg;
	$("#ID").val(stationStandardData[index].id);
	if (deleteFlag == "update") {
		addTitle("statisticsReportUpdate");
		allTable(index);
	} else if (deleteFlag == "delete") {
		showMessge(messageContent["Delete.Confirm"], "model2");
	}
}
function allTable(index){
	createComBody("detailOneBody", statisticsReportTable, statisticsReportData[index], 1);
	$("#save").modal("show");
}

function getUrl(){
	if(deleteFlag == "save"){
		return 'saveStatisticsReport';
	} else if(deleteFlag == "update"){
		return 'updateStatisticsReport';
	} else if(deleteFlag == "delete"){
		return 'deleteStatisticsReport';
	}
}

function confirm(){
	return checkForm("saveForm", statisticsReportTable);
}

function saveStatisticsReport(data){
	if(deleteFlag == "save"){
	     var result = data && data.result;
	     if (result == "Success") {
	    	 showMessge(messageContent["Insert.Success"]);
	    	 $('#save').modal('hide');
	    	 formReset("saveForm");
	     } else if (result == "NotFound"){
	    	 showMessge(messageContent["Insert.Failed"]);
	     } else {
	    	 showMessge(messageContent["Insert.Error"]);
	     }
	     search();
	}else if(deleteFlag == "update"){
	     var result = data && data.result;
	     if (result == "Success"){
	    	 showMessge(messageContent["Update.Success"]);
	    	 $('#save').modal('hide');
	    	 formReset("saveForm");
	     } else if (result == "NotFound"){
	    	 showMessge(messageContent["Update.Failed"]);
	     } else{
	    	 showMessge(messageContent["Update.Error"]);
	     }
	     search();
	}
}
function getData(){
	return {ID: $("#ID").val()};
}
function sure(data){
	if(deleteFlag == "delete"){
		var result = data && data.result;
	    if (result == "Success") {
			showMessge(messageContent["Delete.Success"]);
		} else if (result == "NotFound") {
			showMessge(messageContent["Delete.NotFound"]);
		} else {
			showMessge(messageContent["Delete.Error"]);
		}
	    search();
	} 
}